

import java.awt.DisplayMode;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.WindowConstants;

import com.cloudgarden.layout.AnchorConstraint;
import com.cloudgarden.layout.AnchorLayout;


/**
* Klasa pokazujaca, na srodku, ekran splash'owy konsoli.
*/
public class splash extends javax.swing.JFrame {

	/**
	 * Tworzy i pokazuje nowy ekran.
	 *
	 */
	public String path;
	
	public splash() {
		
	}
	public splash(String p) {
		super();
		path = p;
		initGUI();
	}
	private void initGUI() {
		
		GraphicsEnvironment environment = GraphicsEnvironment.getLocalGraphicsEnvironment();
	    GraphicsDevice device = environment.getDefaultScreenDevice();
	    DisplayMode displayMode = device.getDisplayMode();
		AnchorLayout thisLayout = new AnchorLayout();
		getContentPane().setLayout(thisLayout);
	    this.setLocation(displayMode.getWidth()/2-358/2,displayMode.getHeight()/2-269/2);
		Image image = null;
	    try {
	        // z file
	        File file = new File(path);
	        image = ImageIO.read(file);
	        
	        // ze stream
	        InputStream is = new BufferedInputStream(
	            new FileInputStream(path));
	        image = ImageIO.read(is);
	    
	    } catch (IOException e) {
	    }
	    
	    // Uzywam label zeby wyswietlic image.
	    
	    JLabel label = new JLabel(new ImageIcon(image));
		AnchorLayout labelLayout = new AnchorLayout();
		label.setLayout(labelLayout);
	    getContentPane().add(label, new AnchorConstraint(2, 1001, 1002, 1, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL, AnchorConstraint.ANCHOR_REL));
	    label.setPreferredSize(new java.awt.Dimension(350, 240));

		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			//this.setIconImage(new ImageIcon(getClass().getClassLoader().getResource("splash.png")).getImage());
			this.setUndecorated(false);
			this.setTitle("Preview screen");
			this.addMouseListener(new MouseAdapter() {
				public void mouseClicked(MouseEvent evt) {
					dispose();
				}
			});
			pack();
			this.setSize(358, 269);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	public JLabel gimmiImage(String path) {
		Image image2 = null;
		JLabel label2 = new JLabel("Fake image");
	    try {
	        // z file
	        File file = new File(path);
	        image2 = ImageIO.read(file);
	        
	        // ze stream
	        InputStream is = new BufferedInputStream(
	            new FileInputStream(path));
	        image2 = ImageIO.read(is);
	        label2 = new JLabel(new ImageIcon(image2));
	    
	    } catch (IOException e) {
	    }
	    AnchorLayout labelLayout = new AnchorLayout();
		label2.setLayout(labelLayout);
		return label2;
	}

}
